#!/bin/bash

__rootdir=$(dirname $(readlink -f $(which $0)))
PIDFILE=$__rootdir/md5check.pid
SOCKFILE=$__rootdir/md5check.sock

killpid() {
    local pidfile=$1
    local instance_name=$2
    local signal=${3:-TERM}
    if [[ -f "$pidfile" ]]; then
        local pid=`cat $pidfile`
        if [[ -n "$pid" && -e /proc/$pid/cmdline ]]; then
            echo "find existing $instance_name instance, killing it ($pid)"
            kill -$signal $pid
            sleep 0.1
        fi 
    fi
}


killpid $PIDFILE "md5check.py" INT
export REAL_SCRIPT_NAME=""
echo "spawn-fcgi -d $__rootdir -s $SOCKFILE -P "$PIDFILE" -- $PWD/md5check.py fcgi"
spawn-fcgi -d $__rootdir -s $SOCKFILE -P "$PIDFILE" -- $PWD/md5check.py fcgi
chgrp www-data $SOCKFILE
chmod g+w $SOCKFILE

# vim:ai:et:sts=4:sw=4:
